<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>Vue CLI 3 项目构建基础 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="Vue,">
  

  <meta name="description" content="一、依赖工具# 查看 node 版本node -v# 查看 npm 版本npm -v 二、脚手架vue-cli# 安装 Vue CLI 3.xnpm i -g @vue/cli  安装完 vue-cli 后，我们在你想要创建的项目目录地址下执行构建命令  # my-project 是你的项目名称vue create my-project 目录结构 ├── node_modules     # 项目">
<meta name="keywords" content="Vue">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue CLI 3 项目构建基础">
<meta property="og:url" content="http://blog.poetries.top/2019/06/01/vue-cli3/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、依赖工具# 查看 node 版本node -v# 查看 npm 版本npm -v 二、脚手架vue-cli# 安装 Vue CLI 3.xnpm i -g @vue/cli  安装完 vue-cli 后，我们在你想要创建的项目目录地址下执行构建命令  # my-project 是你的项目名称vue create my-project 目录结构 ├── node_modules     # 项目">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://user-gold-cdn.xitu.io/2018/6/26/1643ca037f818a81">
<meta property="og:image" content="https://user-gold-cdn.xitu.io/2018/6/26/1643ca8799bb4491">
<meta property="og:image" content="https://user-gold-cdn.xitu.io/2018/7/22/164c05d8ad965059">
<meta property="og:image" content="https://user-gold-cdn.xitu.io/2018/7/22/164c15d1f97432b5">
<meta property="og:updated_time" content="2020-08-15T04:25:31.938Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Vue CLI 3 项目构建基础">
<meta name="twitter:description" content="一、依赖工具# 查看 node 版本node -v# 查看 npm 版本npm -v 二、脚手架vue-cli# 安装 Vue CLI 3.xnpm i -g @vue/cli  安装完 vue-cli 后，我们在你想要创建的项目目录地址下执行构建命令  # my-project 是你的项目名称vue create my-project 目录结构 ├── node_modules     # 项目">
<meta name="twitter:image" content="https://user-gold-cdn.xitu.io/2018/6/26/1643ca037f818a81">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、依赖工具"><span class="toc-text">一、依赖工具</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、脚手架vue-cli"><span class="toc-text">二、脚手架vue-cli</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、webpack-在-CLI-3-中的应用"><span class="toc-text">三、webpack 在 CLI 3 中的应用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-与-vue-cli-2-x-的差异"><span class="toc-text">3.1 与 vue-cli 2.x 的差异</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-vue-config-js-的配置"><span class="toc-text">3.2 vue.config.js 的配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-默认插件简介"><span class="toc-text">3.3 默认插件简介</span></a></li></ol></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-vue-cli3" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">Vue CLI 3 项目构建基础</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2019.06.02</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.9k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 8分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="一、依赖工具"><a href="#一、依赖工具" class="headerlink" title="一、依赖工具"></a>一、依赖工具</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 查看 node 版本</span></span><br><span class="line">node -v</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看 npm 版本</span></span><br><span class="line">npm -v</span><br></pre></td></tr></table></figure>
<h2 id="二、脚手架vue-cli"><a href="#二、脚手架vue-cli" class="headerlink" title="二、脚手架vue-cli"></a>二、脚手架vue-cli</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 安装 Vue CLI 3.x</span></span><br><span class="line">npm i -g @vue/cli</span><br></pre></td></tr></table></figure>
<blockquote>
<p>安装完 <code>vue-cli</code> 后，我们在你想要创建的项目目录地址下执行构建命令</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># my-project 是你的项目名称</span></span><br><span class="line">vue create my-project</span><br></pre></td></tr></table></figure>
<p><strong>目录结构</strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">├── node_modules     <span class="comment"># 项目依赖包目录</span></span><br><span class="line">├── public</span><br><span class="line">│   ├── favicon.ico  <span class="comment"># ico图标</span></span><br><span class="line">│   └── index.html   <span class="comment"># 首页模板</span></span><br><span class="line">├── src </span><br><span class="line">│   ├── assets       <span class="comment"># 样式图片目录</span></span><br><span class="line">│   ├── components   <span class="comment"># 组件目录</span></span><br><span class="line">│   ├── views        <span class="comment"># 页面目录</span></span><br><span class="line">│   ├── App.vue      <span class="comment"># 父组件</span></span><br><span class="line">│   ├── main.js      <span class="comment"># 入口文件</span></span><br><span class="line">│   ├── router.js    <span class="comment"># 路由配置文件</span></span><br><span class="line">│   └── store.js     <span class="comment"># vuex状态管理文件</span></span><br><span class="line">├── .gitignore       <span class="comment"># git忽略文件</span></span><br><span class="line">├── .postcssrc.js    <span class="comment"># postcss配置文件</span></span><br><span class="line">├── babel.config.js  <span class="comment"># babel配置文件</span></span><br><span class="line">├── package.json     <span class="comment"># 包管理文件</span></span><br><span class="line">└── yarn.lock        <span class="comment"># yarn依赖信息文件</span></span><br></pre></td></tr></table></figure>
<p><strong>可视化界面</strong></p>
<blockquote>
<p>除了使用上述命令行构建外，<code>vue-cli 3.x</code> 还提供了可视化的操作界面，在项目目录下我们运行如下命令开启图形化界面：</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">vue ui</span><br></pre></td></tr></table></figure>
<p><img src="https://user-gold-cdn.xitu.io/2018/6/26/1643ca037f818a81" alt></p>
<p><img src="https://user-gold-cdn.xitu.io/2018/6/26/1643ca8799bb4491" alt></p>
<h2 id="三、webpack-在-CLI-3-中的应用"><a href="#三、webpack-在-CLI-3-中的应用" class="headerlink" title="三、webpack 在 CLI 3 中的应用"></a>三、webpack 在 CLI 3 中的应用</h2><h3 id="3-1-与-vue-cli-2-x-的差异"><a href="#3-1-与-vue-cli-2-x-的差异" class="headerlink" title="3.1 与 vue-cli 2.x 的差异"></a>3.1 与 vue-cli 2.x 的差异</h3><blockquote>
<p>如果你使用过 <code>vue-cli 2.x</code>，那么你应该了解其构建出的目录会包含相应的 <code>webpack</code>配置文件，但是在 <code>vue-cli 3.x</code> 中你却见不到一份关于 webpack 的配置文件，难道 <code>3.x</code> 抛弃了 webpack？其实不然，<code>3.x</code> 提供了一种开箱即用的模式，即你无需配置 <code>webpack</code> 就可以运行项目，并且它提供了一个 <code>vue.config.js</code> 文件来满足开发者对其封装的 <code>webpack</code> 默认配置的修改</p>
</blockquote>
<p><img src="https://user-gold-cdn.xitu.io/2018/7/22/164c05d8ad965059" alt></p>
<h3 id="3-2-vue-config-js-的配置"><a href="#3-2-vue-config-js-的配置" class="headerlink" title="3.2 vue.config.js 的配置"></a>3.2 vue.config.js 的配置</h3><p><strong>a. baseurl</strong></p>
<blockquote>
<p>你想要将项目地址加一个二级目录，比如：<code>http://localhost:8080/vue/</code>，那么我们需要在 <code>vue.config.js</code> 里配置 <code>baseurl</code> 这一项</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// vue.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    baseUrl: <span class="string">'vue'</span>,</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>其改变的其实是 <code>webpack</code> 配置文件中 <code>output</code> 的 <code>publicPath</code> 项，这时候你重启终端再次打开页面的时候我们首页的<code>url</code> 就会变成带二级目录的形式。</p>
</blockquote>
<p><strong>b. outputDir</strong></p>
<blockquote>
<p>如果你想将构建好的文件打包输出到 <code>output</code> 文件夹下（默认是 <code>dist</code> 文件夹），你可以配置</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// vue.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    outputDir: <span class="string">'output'</span>,</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>然后运行命令 <code>yarn build</code> 进行打包输出，你会发现项目跟目录会创建 <code>output</code> 文件夹， 这其实改变了 <code>webpack</code> 配置中 <code>output</code> 下的 <code>path</code>项，修改了文件的输出路径</p>
</blockquote>
<p><strong>c. productionSourceMap</strong></p>
<blockquote>
<p>该配置项用于设置是否为生产环境构建生成 <code>source map</code>，一般在生产环境下为了快速定位错误信息，我们都会开启 <code>source map</code>：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// vue.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    productionSourceMap: <span class="literal">true</span>,</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>该配置会修改 <code>webpack</code> 中 <code>devtool</code> 项的值为 <code>source-map</code></p>
</blockquote>
<p><strong>d. chainWebpack</strong></p>
<blockquote>
<p><code>chainWebpack</code> 配置项允许我们更细粒度的控制 <code>webpack</code>的内部配置，其集成的是 <code>webpack-chain</code> 这一插件，该插件可以让我们能够使用链式操作来修改配置，比如</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 用于做相应的合并处理</span></span><br><span class="line"><span class="keyword">const</span> merge = <span class="built_in">require</span>(<span class="string">'webpack-merge'</span>);</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// config 参数为已经解析好的 webpack 配置</span></span><br><span class="line">    chainWebpack: <span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">        config.module</span><br><span class="line">            .rule(<span class="string">'images'</span>)</span><br><span class="line">            .use(<span class="string">'url-loader'</span>)</span><br><span class="line">            .tap(<span class="function"><span class="params">options</span> =&gt;</span></span><br><span class="line">                merge(options, &#123;</span><br><span class="line">                  limit: <span class="number">5120</span>,</span><br><span class="line">                &#125;)</span><br><span class="line">            )</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>以上操作我们可以成功修改 webpack 中 module 项里配置 rules 规则为图片下的 url-loader 值，将其 limit 限制改为 5M，修改后的 webpack 配置代码如下：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    <span class="built_in">module</span>: &#123;</span><br><span class="line">        rules: [</span><br><span class="line">            &#123;   </span><br><span class="line">                <span class="comment">/* config.module.rule('images') */</span></span><br><span class="line">                test: <span class="regexp">/\.(png|jpe?g|gif|webp)(\?.*)?$/</span>,</span><br><span class="line">                use: [</span><br><span class="line">                    <span class="comment">/* config.module.rule('images').use('url-loader') */</span></span><br><span class="line">                    &#123;</span><br><span class="line">                        loader: <span class="string">'url-loader'</span>,</span><br><span class="line">                        options: &#123;</span><br><span class="line">                            limit: <span class="number">5120</span>,</span><br><span class="line">                            name: <span class="string">'img/[name].[hash:8].[ext]'</span></span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                ]</span><br><span class="line">            &#125;</span><br><span class="line">        ]</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>e. configureWebpack</strong></p>
<blockquote>
<p>除了上述使用 <code>chainWebpack</code> 来改变 <code>webpack</code> 内部配置外，我们还可以使用 <code>configureWebpack</code> 来进行修改，两者的不同点在于 <code>chainWebpack</code> 是链式修改，而 <code>configureWebpack</code> 更倾向于整体替换和修改。示例代码如下</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// vue.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// config 参数为已经解析好的 webpack 配置</span></span><br><span class="line">    configureWebpack: <span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// config.plugins = []; // 这样会直接将 plugins 置空</span></span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 使用 return 一个对象会通过 webpack-merge 进行合并，plugins 不会置空</span></span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            plugins: []</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>configureWebpack</code> 可以直接是一个对象，也可以是一个函数，如果是对象它会直接使用 <code>webpack-merge</code> 对其进行合并处理，如果是函数，你可以直接使用其 <code>config</code>参数来修改 <code>webpack</code> 中的配置，或者返回一个对象来进行 merge 处理</p>
</blockquote>
<p>你可以在项目目录下运行 <code>vue inspect</code> 来查看你修改后的 <code>webpack</code> 完整配置，当然你也可以缩小审查范围，比如</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 只查看 plugins 的内容</span></span><br><span class="line">vue inspect plugins</span><br></pre></td></tr></table></figure>
<p><strong>f. devServer</strong></p>
<blockquote>
<p><code>vue.config.js</code> 还提供了 <code>devServer</code> 项用于配置 <code>webpack-dev-server</code> 的行为，使得我们可以对本地服务器进行相应配置，我们在命令行中运行的 <code>yarn serve</code> 对应的命令 <code>vue-cli-service serve</code> 其实便是基于 <code>webpack-dev-server</code> 开启的一个本地服务器，其常用配置参数如下</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// vue.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    ...</span><br><span class="line">    </span><br><span class="line">    devServer: &#123;</span><br><span class="line">        open: <span class="literal">true</span>, <span class="comment">// 是否自动打开浏览器页面</span></span><br><span class="line">        host: <span class="string">'0.0.0.0'</span>, <span class="comment">// 指定使用一个 host。默认是 localhost</span></span><br><span class="line">        port: <span class="number">8080</span>, <span class="comment">// 端口地址</span></span><br><span class="line">        https: <span class="literal">false</span>, <span class="comment">// 使用https提供服务</span></span><br><span class="line">        proxy: <span class="literal">null</span>, <span class="comment">// string | Object 代理设置</span></span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 提供在服务器内部的其他中间件之前执行自定义中间件的能力</span></span><br><span class="line">        before: <span class="function"><span class="params">app</span> =&gt;</span> &#123;</span><br><span class="line">          <span class="comment">// `app` 是一个 express 实例</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>当然除了以上参数，其支持所有的 <code>webpack-dev-server</code>中的选项，比如 <code>historyApiFallback</code> 用于重写路由（会在后续的多页应用配置中讲解）、progress 将运行进度输出到控制台等</p>
</blockquote>
<h3 id="3-3-默认插件简介"><a href="#3-3-默认插件简介" class="headerlink" title="3.3 默认插件简介"></a>3.3 默认插件简介</h3><blockquote>
<p>通过对 <code>vue.config.js</code> 的了解，我们知道了 <code>vue-cli 3.x</code>为我们默认封装了项目运行的常用 <code>webpack</code> 配置，那么它给我们提供了哪些默认插件，每一个 <code>plugin</code> 又有着怎样的用途呢？除了使用 <code>vue inspect plugins</code> 我们还可以通过运行 <code>vue ui</code> 进入可视化页面查看，步骤如下</p>
</blockquote>
<ul>
<li>打开可视化页面，点击对应项目进入管理页面（如果没有对应项目，需要导入或新建）</li>
<li>点击侧边栏 <code>Tasks</code> 选项，再点击二级栏 <code>inspect</code> 选项</li>
<li>点击 <code>Run task</code> 按钮执行审查命令</li>
</ul>
<p><img src="https://user-gold-cdn.xitu.io/2018/7/22/164c15d1f97432b5" alt></p>
<blockquote>
<p>最后我们从输出的内容中找到 <code>plugins</code> 数组，其包含了如下插件（配置项已经省略，增加了定义插件的代码）：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// vue-loader是 webpack 的加载器，允许你以单文件组件的格式编写 Vue 组件</span></span><br><span class="line"><span class="keyword">const</span> VueLoaderPlugin = <span class="built_in">require</span>(<span class="string">'vue-loader/lib/plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// webpack 内置插件，用于创建在编译时可以配置的全局常量</span></span><br><span class="line"><span class="keyword">const</span> &#123; DefinePlugin &#125; = <span class="built_in">require</span>(<span class="string">'webpack'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 用于强制所有模块的完整路径必需与磁盘上实际路径的确切大小写相匹配</span></span><br><span class="line"><span class="keyword">const</span> CaseSensitivePathsPlugin = <span class="built_in">require</span>(<span class="string">'case-sensitive-paths-webpack-plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 识别某些类型的 webpack 错误并整理，以提供开发人员更好的体验。</span></span><br><span class="line"><span class="keyword">const</span> FriendlyErrorsPlugin = <span class="built_in">require</span>(<span class="string">'friendly-errors-webpack-plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 将 CSS 提取到单独的文件中，为每个包含 CSS 的 JS 文件创建一个 CSS 文件</span></span><br><span class="line"><span class="keyword">const</span> MiniCssExtractPlugin = <span class="built_in">require</span>(<span class="string">"mini-css-extract-plugin"</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 用于在 webpack 构建期间优化、最小化 CSS文件</span></span><br><span class="line"><span class="keyword">const</span> OptimizeCssnanoPlugin = <span class="built_in">require</span>(<span class="string">'optimize-css-assets-webpack-plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// webpack 内置插件，用于根据模块的相对路径生成 hash 作为模块 id, 一般用于生产环境</span></span><br><span class="line"><span class="keyword">const</span> &#123; HashedModuleIdsPlugin &#125; = <span class="built_in">require</span>(<span class="string">'webpack'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 用于根据模板或使用加载器生成 HTML 文件</span></span><br><span class="line"><span class="keyword">const</span> HtmlWebpackPlugin = <span class="built_in">require</span>(<span class="string">'html-webpack-plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 用于在使用 html-webpack-plugin 生成的 html 中添加 &lt;link rel ='preload'&gt; 或 &lt;link rel ='prefetch'&gt;，有助于异步加载</span></span><br><span class="line"><span class="keyword">const</span> PreloadPlugin = <span class="built_in">require</span>(<span class="string">'preload-webpack-plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 用于将单个文件或整个目录复制到构建目录</span></span><br><span class="line"><span class="keyword">const</span> CopyWebpackPlugin = <span class="built_in">require</span>(<span class="string">'copy-webpack-plugin'</span>);</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    plugins: [</span><br><span class="line">        <span class="comment">/* config.plugin('vue-loader') */</span></span><br><span class="line">        <span class="keyword">new</span> VueLoaderPlugin(), </span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('define') */</span></span><br><span class="line">        <span class="keyword">new</span> DefinePlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('case-sensitive-paths') */</span></span><br><span class="line">        <span class="keyword">new</span> CaseSensitivePathsPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('friendly-errors') */</span></span><br><span class="line">        <span class="keyword">new</span> FriendlyErrorsWebpackPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('extract-css') */</span></span><br><span class="line">        <span class="keyword">new</span> MiniCssExtractPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('optimize-css') */</span></span><br><span class="line">        <span class="keyword">new</span> OptimizeCssnanoPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('hash-module-ids') */</span></span><br><span class="line">        <span class="keyword">new</span> HashedModuleIdsPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('html') */</span></span><br><span class="line">        <span class="keyword">new</span> HtmlWebpackPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('preload') */</span></span><br><span class="line">        <span class="keyword">new</span> PreloadPlugin(),</span><br><span class="line">        </span><br><span class="line">        <span class="comment">/* config.plugin('copy') */</span></span><br><span class="line">        <span class="keyword">new</span> CopyWebpackPlugin()</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2019/03/10/review-nginx/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2019/06/01/vue-single-page-config/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
